package net.dreamlu.util;

import java.io.Serializable;


/**
 * 分页工具类
 * @author chunmeng.lu
 *
 */
public class PageUtil implements Serializable{
	
	private int currentPage;	// 当前页
	private int pageSize = 10;		// 每页显示记录数 常量
	private int totalRecord;	// 总记录数
	private int totalPage;		// 总页数
	private int firstPage;		// 第一页
	private int lastPage;		// 最后一页
	private int prePage;		// 上一页
	private int nextPage;		// 下一页
	private int position;		// 从第几条信息记录 开始查询
	private int begin;			// 开始
	private int end;				// 结束
	private String actionName;	// 请求名
	
	public int getBegin() {
		if(getTotalPage() < 5){
			this.begin = 1;
		}else if(currentPage > 3 && getTotalPage() >= 5){
			this.begin = currentPage - 2;
		}else{
			this.begin = 1;
		}
		return begin;
	}

	public int getEnd() {
		if(getTotalPage() < 5){
			this.end = getTotalPage();
		}else if(currentPage < 3 && getTotalPage() >= 5){
			this.end = 5;
		}else{
			this.end = getTotalPage();
		}
		return end;
	}

	public PageUtil(int totalRecord) {
		this.totalRecord = totalRecord;
	}

	public PageUtil(int currentPage, int totalRecord) {
		this.totalRecord = totalRecord;
		this.currentPage = currentPage;
	}
	
	public PageUtil(int currentPage, int totalRecord, String actionName) {
		this.totalRecord = totalRecord;
		this.currentPage = currentPage;
		this.actionName = actionName;
	}

	public int getCurrentPage() {
		if (this.currentPage < 1)
			this.currentPage = 1;
		if (this.currentPage > this.getTotalPage())
			this.currentPage = this.getTotalPage();

		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalRecord() {
		return totalRecord;
	}

	public void setTotalRecord(int totalRecord) {
		this.totalRecord = totalRecord;
	}

	public int getTotalPage() {
		if (this.getTotalRecord() % pageSize == 0)
			return this.getTotalRecord() / pageSize;
		return this.getTotalRecord() / pageSize + 1;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getFirstPage() {
		return 1;
	}

	public void setFirstPage(int firstPage) {
		this.firstPage = firstPage;
	}

	public int getLastPage() {
		return this.getTotalPage();
	}

	public void setLastPage(int lastPage) {
		this.lastPage = lastPage;
	}

	public int getPrePage() {
		if (this.getCurrentPage() - 1 <= 0)
			return 1;
		return this.getCurrentPage() - 1;
	}

	public void setPrePage(int prePage) {
		this.prePage = prePage;
	}

	public int getNextPage() {
		if (this.getCurrentPage() + 1 >= this.getTotalPage())
			return this.getTotalPage();
		return this.getCurrentPage() + 1;
	}

	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

	public int getPosition() {
		return (this.getCurrentPage() - 1) * pageSize + 1;
	}

	public void setPosition(int position) {
		this.position = position;
	}

	public String getActionName() {
		return actionName;
	}

	public void setActionName(String actionName) {
		this.actionName = actionName;
	}

	public void setBegin(int begin) {
		this.begin = begin;
	}

	public void setEnd(int end) {
		this.end = end;
	}
	
}
